class CreateOrders < ActiveRecord::Migration
  def change
    create_table :orders, :force => true do |t|
      t.string  :number, :limit => 20, :null => true
      t.decimal :total, :precision => 17, :scale => 3, :null => true, :default => 0.0
      t.decimal :item_total,  :precision => 16, :scale => 3, :null => true, :default => 0.0

      t.references :user_info
      
      t.string  :user_name, :limit => 15
      t.string  :user_surname, :limit => 30
      t.string  :user_email, :limit => 50
      t.string  :user_phone, :limit => 16

      t.string    :token, :limit => 60,       :null => true
      t.text      :user_note, :null => true
      t.string    :state, :limit => 15, :default => "in_progress"
      t.timestamp :email_confirmation, :default => false
      t.string    :ip_address, :limit => 20,  :null => true
      t.timestamp :completed_at,            :null => true
      t.timestamp :deleted_at,              :null => true
      t.timestamps
    end

    add_index :orders, :user_info_id
    add_index :orders, :number, :unique => true
  end
end
